//
//  FProgressCell.m
//  SolarSeek
//
//  Created by Erick Fejta on 05/05/13.
//  Copyright 2005 Erick Fejta. All rights reserved.
//

#import "FProgressCell.h"


@implementation FProgressCell

- (id)init {
	if(self = [super initImageCell:nil]) {
		_amount = 0.0;
	}
	return self;
}


- (id)copyWithZone:(NSZone *)zone {
	id o;
	if(o = [super copyWithZone:zone]) {
		[o setFloatValue:_amount];
	}
	return o;
	
}

- (float)floatVaue { return _amount; }
- (id)objectValue { return [NSNumber numberWithFloat:_amount]; }

- (void)setFloatValue:(float)f {
	_amount = f;
}

- (void)setObjectValue:(id)object {
	[self setFloatValue:[object floatValue]];
}

- (void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)view {
	if(_amount > 1.0 || _amount < -1.0)
		return;
	NSRect r = NSInsetRect(frame,5,10);
	NSBezierPath *bp = [NSBezierPath bezierPathWithRect:r];
	NSColor *blue = [NSColor grayColor];
	NSColor *white = [NSColor whiteColor];
	float rc = 0.5, gc = 0.5, bc = 0.5, ac = 1.0;
	NSColor *n = [NSColor colorWithCalibratedRed:rc green:gc blue:bc alpha:ac];
	n = [blue blendedColorWithFraction:_amount*_amount*_amount*_amount ofColor:n];
	if(_amount < 0) {
		blue = [NSColor colorWithCalibratedRed:0.5 green:0.5 blue:0.5 alpha:1.0];
		n = blue;
		_amount *= -1.0;
	}		
	if([self isHighlighted]) {
		blue = [blue highlightWithLevel:0.5];
		white = [white highlightWithLevel:0.5];
		n = [n highlightWithLevel:0.5];
	}
	
	[white set];
	[bp fill];
	[n set];
	[bp stroke];
	
	NSDivideRect(r,&r,&frame,_amount*r.size.width, NSMinXEdge);
	bp = [NSBezierPath bezierPathWithRect:r];
	[n set];
	[bp fill];
//	[blue set];
//	[bp stroke];
	NSRectFill(r);
}

@end
